!function () {
    var str = '', shopobj = {}, Nuabl = JSON.parse(sessionStorage.getItem('Bookers')),
        nbm = $('.header-TextNem').val() * 1, user = JSON.parse(localStorage.getItem('user'));

    shopobj.uid = user.data.id
    renderparticulars()
    function renderparticulars() {
        $.ajax({
            url: 'http://localhost/80edu/api.php/records/detail',
            type: 'get',
            success: function (data) {
                $.each(data.records, function (k, v) {
                    if (v.id == Nuabl) {
                        shopobj.goodsid = v.id, shopobj.goodsname = v.name, shopobj.price = v.price
                        $('.header-title').html(v.name + '<img style="margin-left: 10px;" src="./img/erweimamamama_20190514195522.gif" alt="">')
                        str = '<li>'
                            + '<span>编号：' + v.bianhao + '</span>'
                            + '</li>'
                            + '<li>'
                            + '<span>类型：' + v.leixing + '</span>'
                            + '</li>'
                            + '<li>'
                            + '<span>规格：' + v.guige + '</span>'
                            + '</li>'
                            + '<li>'
                            + '<span>材质：' + v.caizhi + '</span>'
                            + '</li>'
                            + '<li>'
                            + '<span>颜色：' + v.color + '</span>'
                            + '</li>'
                            + '<li>'
                            + '<span>品牌：' + v.pinpai + '</span>'
                            + '</li>'
                            + '<li>'
                            + '<span>型号：' + v.xinghao + '</span>'
                            + '</li>'
                            + '<li>'
                            + '<span>价格：<b>￥' + v.price + ' </b> <s>￥98.0</s> </span>'
                            + '</li>'
                    }
                })
                $('.header-ListText').html(str)
            }
        })
    }
    renderReplyFun()
    function renderReplyFun() {
        var arr = [], arr1 = []
        $.ajax({
            url: 'http://localhost/80edu/api.php/records/reply',
            method: "get",
            data: { filter: 'uid,eq,' + Nuabl },
            success: function (data) {
                $.each(data.records, function (k, v) {
                    arr1.unshift(k)
                    arr.push(
                        '<div class="fk-pdMenberComment">' +
                        '<div class="f-msgBorderMemberImg">' +
                        '<img src="./img/header-000001.png">' +
                        '</div>' +
                        '<div class="pd-pl80">' +
                        '<span class="msgBoard_msgUser_level">' + v.username + '</span>' +
                        '<div class="iconClass1"></div>' +
                        '<div class="msgTime">' + v.time + '</div>' +
                        '<ul class="msgBoard_marginLeft">' +
                        '<li>★</li>' +
                        '<li>★</li>' +
                        '<li>★</li>' +
                        '</ul>' +
                        '<div class="msgBoard_userMsg_reset">' + v.content + '</div>' +
                        '</div>' +
                        '</div>'
                    )
                })
                $('.reply').html(arr.join(''))
                $('.replyNum').html(arr1[0] + 1)
            }
        })
    }
    $('.header-imgToper').click(function () {
        nbm += 1
        $('.header-TextNem').val(nbm)
    })
    $('.header-imgBottom').click(function () {
        if (nbm > 1) {
            nbm--
            $('.header-TextNem').val(nbm)
        }
    })
    $('#buyItNow').on('click', function () {
        shopobj.num = nbm
        location.href = 'buy.html?shopobj=' + encodeURIComponent(JSON.stringify(shopobj))
    })
    $('.buysuan').on('click', function () {
        location.href = 'shopping.html'
    })
    function AJaxGeter() {
        $.ajax({
            url: 'http://localhost/80edu/api.php/records/shopcar',
            method: "get",
            success: function (data) {
                $('.header-last').text('购物车（' + data.records.length + '）')
                console.log(data.records.length)
                localStorage.setItem('nuabAll', JSON.stringify(data.records.length))
            }
        })
    }
    $('#addshopCar').on('click', function () {
        var total = 0, totalpic = 0
        shopobj.num = nbm
        $.ajax({
            url: 'http://localhost/80edu/api.php/records/shopcar',
            method: 'post',
            data: shopobj,
            success: function (data) {
                $.ajax({
                    url: 'http://localhost/80edu/api.php/records/shopcar',
                    method: 'get',
                    data: { filter: 'uid,eq,' + user.data.id },
                    success: function (data) {
                        AJaxGeter()
                        $.each(data.records, function (k, v) {
                            total += v.num
                            totalpic += v.num * v.price
                            $(".header-nublei").html(total)
                            $(".header-piceter").html(totalpic)
                        })
                        $(".header-zhezhao").show()
                    }
                })
            }
        })
    })
    $('.header-duimgRight,.backClick').on('click', function () {
        $(".header-zhezhao").hide()
    })
}();

